// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyViewCurveAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyViewCurveAttributes
//
// Purpose:
//   This class contains the curve view attributes.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ViewCurveAttributes.
//
struct ViewCurveAttributesObject
{
    PyObject_HEAD
    ViewCurveAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewViewCurveAttributes(int);
std::string
PyViewCurveAttributes_ToString(const ViewCurveAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    {   const double *domainCoords = atts->GetDomainCoords();
        snprintf(tmpStr, 1000, "%sdomainCoords = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 2; ++i)
        {
            snprintf(tmpStr, 1000, "%g", domainCoords[i]);
            str += tmpStr;
            if(i < 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *rangeCoords = atts->GetRangeCoords();
        snprintf(tmpStr, 1000, "%srangeCoords = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 2; ++i)
        {
            snprintf(tmpStr, 1000, "%g", rangeCoords[i]);
            str += tmpStr;
            if(i < 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *viewportCoords = atts->GetViewportCoords();
        snprintf(tmpStr, 1000, "%sviewportCoords = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 4; ++i)
        {
            snprintf(tmpStr, 1000, "%g", viewportCoords[i]);
            str += tmpStr;
            if(i < 3)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    const char *domainScale_values[] = {"LINEAR", "LOG"};
    snprintf(tmpStr, 1000, "%sdomainScale = %s%s  # LINEAR, LOG\n", prefix, prefix, domainScale_values[atts->GetDomainScale()]);
    str += tmpStr;
    const char *rangeScale_values[] = {"LINEAR", "LOG"};
    snprintf(tmpStr, 1000, "%srangeScale = %s%s  # LINEAR, LOG\n", prefix, prefix, rangeScale_values[atts->GetRangeScale()]);
    str += tmpStr;
    return str;
}

static PyObject *
ViewCurveAttributes_Notify(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_SetDomainCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetDomainCoords();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 2)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 2)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 2 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the domainCoords in the object as modified.
    obj->data->SelectDomainCoords();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_GetDomainCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the domainCoords.
    PyObject *retval = PyTuple_New(2);
    const double *domainCoords = obj->data->GetDomainCoords();
    for(int i = 0; i < 2; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(domainCoords[i]));
    return retval;
}

/*static*/ PyObject *
ViewCurveAttributes_SetRangeCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetRangeCoords();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 2)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 2)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 2 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the rangeCoords in the object as modified.
    obj->data->SelectRangeCoords();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_GetRangeCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the rangeCoords.
    PyObject *retval = PyTuple_New(2);
    const double *rangeCoords = obj->data->GetRangeCoords();
    for(int i = 0; i < 2; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(rangeCoords[i]));
    return retval;
}

/*static*/ PyObject *
ViewCurveAttributes_SetViewportCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetViewportCoords();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 4)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 4)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 4 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the viewportCoords in the object as modified.
    obj->data->SelectViewportCoords();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_GetViewportCoords(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the viewportCoords.
    PyObject *retval = PyTuple_New(4);
    const double *viewportCoords = obj->data->GetViewportCoords();
    for(int i = 0; i < 4; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(viewportCoords[i]));
    return retval;
}

/*static*/ PyObject *
ViewCurveAttributes_SetDomainScale(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;

    int ival = -999;
    if (PySequence_Check(args) && !PyArg_ParseTuple(args, "i", &ival))
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    else if (PyNumber_Check(args) && (ival = PyLong_AsLong(args)) == -1 && PyErr_Occurred())
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    if (ival == -999)
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");

    // Set the domainScale in the object.
    if(ival >= 0 && ival <= 1)
        obj->data->SetDomainScale(ival);
    else
    {
        return PyErr_Format(PyExc_IndexError, "An invalid  value was given. "
                        "Valid values are in the range of [0,1]. "
                        "You can also use the following names: "
                        "\"LINEAR\", \"LOG\"\n");
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_GetDomainScale(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetDomainScale()));
    return retval;
}

/*static*/ PyObject *
ViewCurveAttributes_SetRangeScale(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;

    int ival = -999;
    if (PySequence_Check(args) && !PyArg_ParseTuple(args, "i", &ival))
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    else if (PyNumber_Check(args) && (ival = PyLong_AsLong(args)) == -1 && PyErr_Occurred())
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    if (ival == -999)
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");

    // Set the rangeScale in the object.
    if(ival >= 0 && ival <= 1)
        obj->data->SetRangeScale(ival);
    else
    {
        return PyErr_Format(PyExc_IndexError, "An invalid  value was given. "
                        "Valid values are in the range of [0,1]. "
                        "You can also use the following names: "
                        "\"LINEAR\", \"LOG\"\n");
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ViewCurveAttributes_GetRangeScale(PyObject *self, PyObject *args)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetRangeScale()));
    return retval;
}



PyMethodDef PyViewCurveAttributes_methods[VIEWCURVEATTRIBUTES_NMETH] = {
    {"Notify", ViewCurveAttributes_Notify, METH_VARARGS},
    {"SetDomainCoords", ViewCurveAttributes_SetDomainCoords, METH_VARARGS},
    {"GetDomainCoords", ViewCurveAttributes_GetDomainCoords, METH_VARARGS},
    {"SetRangeCoords", ViewCurveAttributes_SetRangeCoords, METH_VARARGS},
    {"GetRangeCoords", ViewCurveAttributes_GetRangeCoords, METH_VARARGS},
    {"SetViewportCoords", ViewCurveAttributes_SetViewportCoords, METH_VARARGS},
    {"GetViewportCoords", ViewCurveAttributes_GetViewportCoords, METH_VARARGS},
    {"SetDomainScale", ViewCurveAttributes_SetDomainScale, METH_VARARGS},
    {"GetDomainScale", ViewCurveAttributes_GetDomainScale, METH_VARARGS},
    {"SetRangeScale", ViewCurveAttributes_SetRangeScale, METH_VARARGS},
    {"GetRangeScale", ViewCurveAttributes_GetRangeScale, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ViewCurveAttributes_dealloc(PyObject *v)
{
   ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ViewCurveAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyViewCurveAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "domainCoords") == 0)
        return ViewCurveAttributes_GetDomainCoords(self, NULL);
    if(strcmp(name, "rangeCoords") == 0)
        return ViewCurveAttributes_GetRangeCoords(self, NULL);
    if(strcmp(name, "viewportCoords") == 0)
        return ViewCurveAttributes_GetViewportCoords(self, NULL);
    if(strcmp(name, "domainScale") == 0)
        return ViewCurveAttributes_GetDomainScale(self, NULL);
    if(strcmp(name, "LINEAR") == 0)
        return PyInt_FromLong(long(0));
    else if(strcmp(name, "LOG") == 0)
        return PyInt_FromLong(long(1));

    if(strcmp(name, "rangeScale") == 0)
        return ViewCurveAttributes_GetRangeScale(self, NULL);
    if(strcmp(name, "LINEAR") == 0)
        return PyInt_FromLong(long(0));
    else if(strcmp(name, "LOG") == 0)
        return PyInt_FromLong(long(1));



    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyViewCurveAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyViewCurveAttributes_methods[i].ml_name),
                PyString_FromString(PyViewCurveAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyViewCurveAttributes_methods, self, name);
}

int
PyViewCurveAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "domainCoords") == 0)
        obj = ViewCurveAttributes_SetDomainCoords(self, args);
    else if(strcmp(name, "rangeCoords") == 0)
        obj = ViewCurveAttributes_SetRangeCoords(self, args);
    else if(strcmp(name, "viewportCoords") == 0)
        obj = ViewCurveAttributes_SetViewportCoords(self, args);
    else if(strcmp(name, "domainScale") == 0)
        obj = ViewCurveAttributes_SetDomainScale(self, args);
    else if(strcmp(name, "rangeScale") == 0)
        obj = ViewCurveAttributes_SetRangeScale(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ViewCurveAttributes_print(PyObject *v, FILE *fp, int flags)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)v;
    fprintf(fp, "%s", PyViewCurveAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ViewCurveAttributes_str(PyObject *v)
{
    ViewCurveAttributesObject *obj = (ViewCurveAttributesObject *)v;
    return PyString_FromString(PyViewCurveAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ViewCurveAttributes_Purpose = "This class contains the curve view attributes.";
#else
static char *ViewCurveAttributes_Purpose = "This class contains the curve view attributes.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ViewCurveAttributesType,         \
                  "ViewCurveAttributes",           \
                  ViewCurveAttributesObject,       \
                  ViewCurveAttributes_dealloc,     \
                  ViewCurveAttributes_print,       \
                  PyViewCurveAttributes_getattr,   \
                  PyViewCurveAttributes_setattr,   \
                  ViewCurveAttributes_str,         \
                  ViewCurveAttributes_Purpose,     \
                  ViewCurveAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ViewCurveAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ViewCurveAttributesType
         || Py_TYPE(other) != &ViewCurveAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ViewCurveAttributes *a = ((ViewCurveAttributesObject *)self)->data;
    ViewCurveAttributes *b = ((ViewCurveAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ViewCurveAttributes *defaultAtts = 0;
static ViewCurveAttributes *currentAtts = 0;

static PyObject *
NewViewCurveAttributes(int useCurrent)
{
    ViewCurveAttributesObject *newObject;
    newObject = PyObject_NEW(ViewCurveAttributesObject, &ViewCurveAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ViewCurveAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ViewCurveAttributes(*defaultAtts);
    else
        newObject->data = new ViewCurveAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapViewCurveAttributes(const ViewCurveAttributes *attr)
{
    ViewCurveAttributesObject *newObject;
    newObject = PyObject_NEW(ViewCurveAttributesObject, &ViewCurveAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ViewCurveAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ViewCurveAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewViewCurveAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ViewCurveAttributesMethods[] = {
    {"ViewCurveAttributes", ViewCurveAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ViewCurveAttributesObserver = 0;

std::string
PyViewCurveAttributes_GetLogString()
{
    std::string s("ViewCurveAtts = ViewCurveAttributes()\n");
    if(currentAtts != 0)
        s += PyViewCurveAttributes_ToString(currentAtts, "ViewCurveAtts.", true);
    return s;
}

static void
PyViewCurveAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ViewCurveAtts = ViewCurveAttributes()\n");
        s += PyViewCurveAttributes_ToString(currentAtts, "ViewCurveAtts.", true);
        cb(s);
    }
}

void
PyViewCurveAttributes_StartUp(ViewCurveAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyViewCurveAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ViewCurveAttributesObserver == 0)
    {
        ViewCurveAttributesObserver = new ObserverToCallback(subj,
            PyViewCurveAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyViewCurveAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ViewCurveAttributesObserver;
    ViewCurveAttributesObserver = 0;
}

PyMethodDef *
PyViewCurveAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ViewCurveAttributesMethods;
}

bool
PyViewCurveAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &ViewCurveAttributesType);
}

ViewCurveAttributes *
PyViewCurveAttributes_FromPyObject(PyObject *obj)
{
    ViewCurveAttributesObject *obj2 = (ViewCurveAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyViewCurveAttributes_New()
{
    return NewViewCurveAttributes(0);
}

PyObject *
PyViewCurveAttributes_Wrap(const ViewCurveAttributes *attr)
{
    return WrapViewCurveAttributes(attr);
}

void
PyViewCurveAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    ViewCurveAttributesObject *obj2 = (ViewCurveAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyViewCurveAttributes_SetDefaults(const ViewCurveAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ViewCurveAttributes(*atts);
}

